<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
</head>
<body>
<style>
    html, body{background-color:#FFF!important;}
    .modal-body{background-color:#fff;padding:15px}
    .page-header{margin-top:15px!important;}
    .add_button{border-top:1px solid #eee;padding-top:15px;}
    .config_img {
        height:65px;
        margin-top: 15px;
    }
</style>

<div class="modal-body">

    <fieldset class=" layui-field-title" >
        <legend>修改门票</legend>
    </fieldset>


    <form class="layui-form layui-form-pane form-horizontal" action="" >
        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">*标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" placeholder="标题" class="layui-input" value="{$detail.title}">
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">缩略图:</label>
            <div class="layui-col-md7">
                <div class="input-group ">
                    <input type="text" id="thumb" name="thumb" value="{$detail.thumb}" class="layui-input" autocomplete="off">
                    <span class="input-group-btn">
                        <button class="btn btn-default" id="upload" type="button" data-original-title="" title="">选择图片</button>
                    </span>
                </div>
                <img class="config_img thumb" src="/static/images/nopic-107.png" >
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">门票类型</label>
            <div class="layui-col-md4">
                <select name="type" lay-filter="aihao">
                    {volist name="tickets_type" id="vo"}
                        <option value="{$key}" {if condition="$detail['type'] eq $key"} selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>

            <label class="layui-form-label layui-col-md-offset1">*有效期(天)</label>
            <div class="layui-col-md4">
                <input type="number" name="validity" placeholder="有效期" class="layui-input" value="{$detail.validity}">
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">入园时间</label>
            <div class="layui-col-md4">
                <input type="text" name="time_range" class="layui-input" id="test" placeholder=" - " value="{$detail.time_range}" >
            </div>

            <label class="layui-form-label layui-col-md-offset1">入园地址</label>
            <div class="layui-col-md4">
                <input type="text" name="address" placeholder="入园地址" class="layui-input" value="{$detail.address}">
            </div>
        </div>


        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">*价格</label>
            <div class="layui-col-md4">
                <input type="number" step="0.01" name="price" placeholder="价格" class="layui-input" value="{$detail.price}">
            </div>

            <label class="layui-form-label  layui-col-md-offset1">检票次数</label>
            <div class="layui-col-md4">
                <input type="number" name="degree" placeholder="检票次数" class="layui-input" value="{$detail.degree}">
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">库存</label>
            <div class="layui-col-md4">
                <input type="number"  name="inventory" placeholder="库存" class="layui-input" value="{$detail.inventory}">
            </div>

            <label class="layui-form-label  layui-col-md-offset1">已售</label>
            <div class="layui-col-md4">
                <input type="number" name="soldout" placeholder="已售" class="layui-input" value="{$detail.soldout}">
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">排序</label>
            <div class="layui-col-md4">
                <input type="number"  name="sort" placeholder="排序" class="layui-input" value="{$detail.sort}">
            </div>

            <label class="layui-form-label layui-col-md-offset1">状态</label>
            <div class="layui-col-md4">
                <select name="status" lay-filter="aihao">
                {volist name="enable_status" id="vo"}
                <option value="{$key}" {if condition="$detail['status'] eq $key"} selected {/if}>{$vo}</option>
                {/volist}
                </select>
            </div>
        </div>

        <!--图文模型&单页模型-->
        <div class="layui-form-item" >
            <label class="layui-form-label">*详细介绍:</label>
            <div class="layui-col-md8">
                <textarea id="content"  >{$detail.content}</textarea>
            </div>
        </div>
        <input type="hidden" name="id" value="{$detail.id}">
    </form>

</div>
<div class="add_button">
    <div class="layui-form-item">
        <div class="layui-col-md-offset1">
            <a type="button" class="layui-btn layui-btn-primary" href="{:URL('tickets/tickets/index')}" >取消</a>
            <button type="button" class="layui-btn" id="newsave" >保存</button>
        </div>
    </div>
</div>


<script>
    var newModal = new yii.modal();
    //文件页面
    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail'
            }
        });
    });

    newModal.on("upload",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src",images)
    });


    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form','tinymce','laydate'], function() {
        var form = layui.form
            , layer = layui.layer;
        var tinymce = layui.tinymce;

        var laydate = layui.laydate;
        //时间范围
        laydate.render({
            elem: '#test'
            ,type: 'time'
            ,range: true
        });

        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {

        });

        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            $.ajax({
                type:'post',
                url:"{:URL('tickets/tickets/doTickets')}",
                data:data,
                dataType:'JSON',
                success:function (res) {
                    if(res.code!=0){
                        layer.alert(res.msg);
                    }else{
                        window.location.href = "{:URL('tickets/tickets/index')}";
                    }
                },
                error:function (res) {
                }
            });

        })

        layui.form.render('select');
        form.render();
    });
</script>

</body>
</html>